//
//  HomeInfoDataView.m
//  Ginix
//
//  Created by 冯志强 on 2025/3/16.
//

#import "HomeInfoDataView.h"

@interface HomeInfoDataView()
@property (nonatomic,strong) UIView * bgView;
@property (nonatomic,strong) UIImageView * iconView;
@property (nonatomic,strong) UILabel * timeLabel;
@property (nonatomic,strong) UIView * line;
@property (nonatomic,strong) UIButton * nextBtn;
@property (nonatomic,strong) UILabel * infoLabel;
@end

@implementation HomeInfoDataView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
   
    self.backgroundColor = UIColor.clearColor;
    [self addSubview:self.bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(@0);
        make.size.mas_offset(CGSizeMake(330 * FMScaleX, 54 * FMScaleX));
        make.top.mas_offset(10 * FMScaleX);
    }];
    [self.bgView addSubview:self.iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(64 * FMScaleX, 16 * FMScaleX));
        make.left.mas_offset(10 * FMScaleX);
        make.top.mas_offset(10 * FMScaleX);
    }];
    [self.bgView addSubview:self.timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_bottom).offset(6 * FMScaleX);
        make.centerX.equalTo(self.iconView);
    }];
    [self.bgView addSubview:self.line];
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(1, 22 * FMScaleX));
        make.centerY.equalTo(@0);
        make.left.equalTo(self.iconView.mas_right).offset(10 * FMScaleX);
    }];
    [self.bgView addSubview:self.nextBtn];
    [_nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30 * FMScaleX, 30 * FMScaleX));
        make.centerY.equalTo(@0);
        make.right.mas_offset(- 10* FMScaleX);
    }];
    [self.bgView addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(@0);
        make.left.equalTo(self.line.mas_right).offset(10 * FMScaleX);
        make.right.equalTo(self.nextBtn.mas_left).offset(-10 * FMScaleX);
    }];
}

-(void)setInfoModel:(HomeSleepModel *)infoModel{
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@更新",infoModel.time.length > 0 ? infoModel.time : @"--"];
    NSAttributedString *formattedInfo = [NSString formatHealthInfoWithHeartRate:infoModel.heart bloodOxygen:infoModel.q2 temper:infoModel.temp hrv:infoModel.heartRota];
    self.infoLabel.attributedText = formattedInfo;
}


-(UIView *)bgView{
    
    if (!_bgView) {
        _bgView = [[UIView alloc]init];
        [_bgView setCornerRadius:4 * FMScaleX];
        _bgView.backgroundColor = RDRGB(0xF3EDE7);
    }
    return _bgView;
}
-(UIImageView *)iconView{
    
    if (!_iconView) {
        _iconView = [[UIImageView alloc]init];
        _iconView.image = [UIImage imageNamed:@"Home_data_icon"];
    }
    return _iconView;
}
-(UILabel *)timeLabel{
    
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = Regular(10);
        _timeLabel.textColor = RDRGB(0x999999);
    }
    return _timeLabel;
}
-(UIView *)line{
    
    if (!_line) {
        _line = [[UIView alloc]init];
        _line.backgroundColor = RDRGB(0xEAE2D9);
    }
    return _line;
}
-(UIButton *)nextBtn{
    
    if (!_nextBtn) {
        _nextBtn = [[UIButton alloc]init];
        [_nextBtn setImage:[UIImage imageNamed:@"Home_data_btn"] forState:UIControlStateNormal];
    }
    return _nextBtn;
}
-(UILabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc]init];
        _infoLabel.textColor = RDRGB(0x333333);
        _infoLabel.font = Regular(14);
//        _infoLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _infoLabel;
}
@end
